# -*- coding: utf-8 -*-
# author: zhanghao
# time: 2023-12-26
# info: 这是主函数文件

# This is a pokemon Python script.
from multiprocessing import Pipe

from core.monitor import Monitor
from core.master import Master
from core.slaver import Slaver
from config.config import Config
from api.task_api import app
from api.task_api import task_manager

import uvicorn

# 初始化配置
url='http://case.quanyoukeji.com/api/ocr/getRules'
config = Config(url)
config.initConfig()


# main
if __name__ == '__main__':
    # 启动子进程，用于执行任务
    conn_main, conn_sub = Pipe()

    task_manager.addPipe(conn_main)

    monitor = Monitor(conn_sub, config)
    monitor.start()

    # 启动master线程，用于查找任务，分配任务
    master = Master(conn_main)
    master.start()

    port = 8866
    url = 'http://case.quanyoukeji.com/api/ocr/getLists'

    # 启动结果发送线程
    slaver = Slaver(url)
    slaver.start()

    # 启动应用
    uvicorn.run(
        app=app,
        host="0.0.0.0",
        port=port
    )

    monitor.join()
    master.join()
    slaver.join()



